/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketManager.controller;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import ticketManager.ejb.UserDAO;
import ticketManager.model.ManagerUser;
import ticketManager.model.UserGroup;

/**
 *
 * @author lenovo
 */
@Named
@RequestScoped
public class ModifyUserController {
    @EJB
    UserDAO uDAO;
    private String userName;
    private String newPassword;
    
    
    public void remove()
    {   FacesContext ctx = FacesContext.getCurrentInstance();
        Long id=((ManagerUser)ctx.getExternalContext().getSessionMap().get("user")).getId();
        ManagerUser u = uDAO.getUserById(id);
        uDAO.removeUser(u);
      
    }
   public String modifyName()
   {
        FacesContext ctx = FacesContext.getCurrentInstance();
        Long id=((ManagerUser)ctx.getExternalContext().getSessionMap().get("user")).getId();
        String name=((ManagerUser)ctx.getExternalContext().getSessionMap().get("user")).getUserName();
        ManagerUser u = uDAO.getUserById(id);
        
        uDAO.updateName(id, name);
        return "success";
   }  
         
    public String modifyPassword()
    {
         FacesContext ctx = FacesContext.getCurrentInstance();
        Long id=((ManagerUser)ctx.getExternalContext().getSessionMap().get("user")).getId();
        String password=((ManagerUser)ctx.getExternalContext().getSessionMap().get("user")).getPassword();
        ManagerUser u = uDAO.getUserById(id);
        uDAO.updatePassword(id, password) ;
        return "success";
        } 

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getNewPassword() {
        return newPassword;
    }

    public void setNewPassword(String newPassword) {
        this.newPassword = newPassword;
    }
   
}

